package com.ease.framework.gef4p.editparts {
   import com.ease.common.models.IModel;
   import com.ease.framework.gef.EditPart;
   import com.ease.framework.gef4g.GraphicalViewport;
   import com.ease.framework.gef4g.IGraphicalEditor;
   import com.ease.framework.workbench.Workbench;

   import mx.collections.ArrayCollection;
   import mx.core.UIComponent;

   public class AnnotationContainerEditPart extends EditPart {
      protected var annotations:ArrayCollection = new ArrayCollection();

      public function AnnotationContainerEditPart(obj:IModel) {
         super(obj);
      }

      public function addAnnotationEditPart(act:AnnotationEditPart):void {
         var viewport:GraphicalViewport = GraphicalViewport(IGraphicalEditor(Workbench.instance.currentEditor).getGraphicalViewer().getViewport());

         annotations.addItem(act);
         act.refreashFigure();

         if (act.figure.x + act.figure.width > viewport.width)
            viewport.width = act.figure.x + act.figure.width + 100;
         if (act.figure.y + act.figure.height > viewport.height)
            viewport.height = act.figure.y + act.figure.height + 100;

         this.figure.addChild(act.figure as UIComponent);
      }

      public function removeAnnotationEditPart(act:AnnotationEditPart):void {
         if (annotations.contains(act)) {
            annotations.removeItemAt(annotations.getItemIndex(act));
         }
         UIComponent(figure).removeChild(act.figure as UIComponent);
      }
   }
}